package swingxrcp.framework.client.action;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 基于HttpURLConnection的传输器实现
 *
 * @author liangfei
 * @since 2008-10-26
 */
public class HttpURLConnectionTransporter extends HttpTransporter {

	public HttpURLConnectionTransporter(String host, int port, String context,
			String suffix) {
		super(host, port, context, suffix);
	}

	@Override
	protected InputStream doTransport(String url, Serializable object) throws IOException {
		HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
		try {
			conn.setRequestMethod("POST");
			conn.setDoOutput(true);
			conn.setDoInput(true);
			serializer.serialize(object, conn.getOutputStream());
			return conn.getInputStream();
		} finally {
			conn.disconnect();
		}
	}

}
